//
//  VistorTableViewController.swift
//  weibo 666
//mac
//  Created by  on 15/11/6.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit
class VistorTableViewController : UITableViewController {
    private var userLogin = UserAccountViewModel.sharedUserAccount.userLogin
    
    var vistorView: VistorView?
    
    override func loadView() {
        userLogin ? super.loadView() : setUpVistorView()
    }
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        print(vistorView)
    }
    
//    设置访客视图
    private func setUpVistorView () {
        
        vistorView = VistorView()
        view = vistorView
//        
////        添加监听方法
        vistorView?.registerButton.addTarget(self, action: "visitorViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        vistorView?.loginButton.addTarget(self, action: "visitorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        
        
//        设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visitorViewDidLogin")
        
    }
    
}
// MARK: - 访客视图监听方法
extension VistorTableViewController {
    
    func visitorViewDidRegister() {
        print("注册")
    }
    
    func visitorViewDidLogin() {
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        
        presentViewController(nav, animated: true, completion: nil)
    }
}
